package top.buaarobot.webserver.repository;

import top.buaarobot.webserver.domain.Comment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public interface CommentRepository extends JpaRepository<Comment, Integer> {
    @Query(value = "select * from comment where father_id = ?1 and comment_id = -1 order by time desc", nativeQuery = true)
    public Iterable<Comment> searchByFatherId(int blogId);

    @Query(value = "select * from comment where comment_id = ?1 order by time", nativeQuery = true)
    public Iterable<Comment> searchByCommentId(int commentId);

    @Query(value = "select * from comment where user_id = ?1 order by time desc", nativeQuery = true)
    public Iterable<Comment> searchByUserId(int userId);

    @Transactional
    public void deleteAllByCommentId(int commentId);
}
